home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / src_1218.zip / CONFIG.C < prev    next >
C/C++ Source or Header  |  1991-12-16  |  19KB  |  832 lines

  1. /* A collection of stuff heavily dependent on the configuration info
  2.  * in config.h. The idea is that configuration-dependent tables should
  3.  * be located here to avoid having to pepper lots of .c files with #ifdefs,
  4.  * requiring them to include config.h and be recompiled each time config.h
  5.  * is modified.
  6.  *
  7.  * Copyright 1991 Phil Karn, KA9Q
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <dos.h>
  12. #include "global.h"
  13. #include "config.h"
  14. #include "mbuf.h"
  15. #include "timer.h"
  16. #include "proc.h"
  17. #include "iface.h"
  18. #include "ip.h"
  19. #include "tcp.h"
  20. #include "udp.h"
  21. #ifdef    ARCNET
  22. #include "arcnet.h"
  23. #endif
  24. #include "lapb.h"
  25. #include "ax25.h"
  26. #include "enet.h"
  27. #include "kiss.h"
  28. #include "nr4.h"
  29. #include "netrom.h"
  30. #include "pktdrvr.h"
  31. #include "ppp.h"
  32. #include "slip.h"
  33. #include "arp.h"
  34. #include "icmp.h"
  35. #include "hardware.h"    /***/
  36. #include "usock.h"
  37. #include "cmdparse.h"
  38. #include "commands.h"
  39. #include "mailbox.h"
  40. #include "ax25mail.h"
  41. #include "nr4mail.h"
  42. #include "tipmail.h"
  43. #include "daemon.h"
  44. #include "bootp.h"
  45.  
  46. int dotest __ARGS((int argc,char *argv[],void *p));    /**/
  47. static int dostart __ARGS((int argc,char *argv[],void *p));
  48. static int dostop __ARGS((int argc,char *argv[],void *p));
  49.  
  50. #ifdef    AX25
  51. static void axip __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  52.     char *dest,struct mbuf *bp,int mcast));
  53. static void axarp __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  54.     char *dest,struct mbuf *bp,int mcast));
  55. static void axnr __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  56.     char *dest,struct mbuf *bp,int mcast));
  57. #endif
  58.  
  59. struct mbuf *Hopper;
  60. unsigned Nsessions = NSESSIONS;
  61.  
  62. /* Free memory threshold, below which things start to happen to conserve
  63.  * memory, like garbage collection, source quenching and refusing connects
  64.  */
  65. int32 Memthresh = MTHRESH;
  66.  
  67. int Nibufs = NIBUFS;        /* Number of interrupt buffers */
  68. unsigned Ibufsize = IBUFSIZE;    /* Size of each interrupt buffer */
  69.  
  70. /* Transport protocols atop IP */
  71. struct iplink Iplink[] = {
  72.     TCP_PTCL,    tcp_input,
  73.     UDP_PTCL,    udp_input,
  74.     ICMP_PTCL,    icmp_input,
  75.     IP_PTCL,    ipip_recv,
  76.     0,        0
  77. };
  78.  
  79. /* Transport protocols atop ICMP */
  80. struct icmplink Icmplink[] = {
  81.     TCP_PTCL,    tcp_icmp,
  82.     0,        0
  83. };
  84.  
  85. /* ARP protocol linkages */
  86. struct arp_type Arp_type[NHWTYPES] = {
  87. #ifdef    NETROM
  88.     AXALEN, 0, 0, 0, NULLCHAR, pax25, setcall,    /* ARP_NETROM */
  89. #else
  90.     0, 0, 0, 0, NULLCHAR,NULL,NULL,
  91. #endif
  92.  
  93. #ifdef    ETHER
  94.     EADDR_LEN,IP_TYPE,ARP_TYPE,1,Ether_bdcst,pether,gether, /* ARP_ETHER */
  95. #else
  96.     0, 0, 0, 0, NULLCHAR,NULL,NULL,
  97. #endif
  98.  
  99.     0, 0, 0, 0, NULLCHAR,NULL,NULL,            /* ARP_EETHER */
  100.  
  101. #ifdef    AX25
  102.     AXALEN, PID_IP, PID_ARP, 10, Ax25multi[0], pax25, setcall,
  103. #else
  104.     0, 0, 0, 0, NULLCHAR,NULL,NULL,            /* ARP_AX25 */
  105. #endif
  106.  
  107.     0, 0, 0, 0, NULLCHAR,NULL,NULL,            /* ARP_PRONET */
  108.  
  109.     0, 0, 0, 0, NULLCHAR,NULL,NULL,            /* ARP_CHAOS */
  110.  
  111.     0, 0, 0, 0, NULLCHAR,NULL,NULL,            /* ARP_IEEE802 */
  112.  
  113. #ifdef    ARCNET
  114.     AADDR_LEN, ARC_IP, ARC_ARP, 1, ARC_bdcst, parc, garc, /* ARP_ARCNET */
  115. #else
  116.     0, 0, 0, 0, NULLCHAR,NULL,NULL,
  117. #endif
  118.  
  119.     0, 0, 0, 0, NULLCHAR,NULL,NULL,            /* ARP_APPLETALK */
  120. };
  121.  
  122. #ifdef    AX25
  123. /* Linkage to network protocols atop ax25 */
  124. struct axlink Axlink[] = {
  125.     PID_IP,        axip,
  126.     PID_ARP,    axarp,
  127. #ifdef    NETROM
  128.     PID_NETROM,    axnr,
  129. #endif
  130.     PID_NO_L3,    axnl3,
  131.     0,        NULL,
  132. };
  133. #endif
  134.  
  135. #ifdef    MAILBOX
  136. void (*Listusers) __ARGS((int s)) = listusers;
  137. #else
  138. void (*Listusers) __ARGS((int s)) = NULL;
  139. #endif
  140.  
  141. #ifndef    BOOTP
  142. int WantBootp = 0;
  143.  
  144. int
  145. bootp_validPacket(ip,bpp)
  146. struct ip *ip;
  147. struct mbuf **bpp;
  148. {
  149.     return 0;
  150. }
  151. #endif
  152.  
  153. /* daemons to be run at startup time */
  154. struct daemon Daemons[] = {
  155.     "killer",    512,    killer,
  156.     "gcollect",    256,    gcollect,
  157.     "timer",    1024,    timerproc,
  158.     "network",    1536,    network,
  159.     "keyboard",    250,    keyboard,
  160.     NULLCHAR,    0,    NULLVFP
  161. };
  162.  
  163. struct iftype Iftypes[] = {
  164.     /* This entry must be first, since Loopback refers to it */
  165.     "None",        NULL,        NULL,        NULL,
  166.     NULL,        CL_NONE,    0,
  167.  
  168. #ifdef    AX25
  169.     "AX25",        ax_send,    ax_output,    pax25,
  170.     setcall,    CL_AX25,    AXALEN,
  171. #endif
  172.  
  173. #ifdef    SLIP
  174.     "SLIP",        slip_send,    NULL,        NULL,
  175.     NULL,        CL_NONE,    0,
  176. #endif
  177.  
  178. #ifdef    ETHER
  179.     /* Note: NULL is specified for the scan function even though
  180.      * gether() exists because the packet drivers don't support
  181.      * address setting.
  182.      */
  183.     "Ethernet",    enet_send,    enet_output,    pether,
  184.     NULL,        CL_ETHERNET,    EADDR_LEN,
  185. #endif
  186.  
  187. #ifdef    NETROM
  188.     "NETROM",    nr_send,    NULL,        pax25,
  189.     setcall,    CL_NETROM,    AXALEN,
  190. #endif
  191.  
  192. #ifdef    SLFP
  193.     "SLFP",        pk_send,    NULL,        NULL,
  194.     NULL,        CL_NONE,    0,
  195. #endif
  196.  
  197. #ifdef    PPP
  198.     "PPP",        ppp_send,    ppp_output,    NULL,
  199.     NULL,        CL_PPP,    0,
  200. #endif
  201.  
  202.     NULLCHAR
  203. };
  204.  
  205. /* Command lookup and branch tables */
  206. struct cmds Cmds[] = {
  207.     /* The "go" command must be first */
  208.     "",        go,        0, 0, NULLCHAR,
  209. #ifndef    AMIGA
  210.     "!",        doshell,    0, 0, NULLCHAR,
  211. #endif
  212.     "abort",    doabort,    0, 0, NULLCHAR,
  213. #ifdef    AMIGA
  214.     "amiga",    doamiga,    0, 0, NULLCHAR,
  215. #endif
  216. #if    (defined(MAC) && defined(APPLETALK))
  217.     "applestat",    doatstat,    0,    0, NULLCHAR,
  218. #endif
  219. #if    (defined(AX25) || defined(ETHER) || defined(APPLETALK))
  220.     "arp",        doarp,        0, 0, NULLCHAR,
  221. #endif
  222. #ifdef    ASY
  223.     "asystat",    doasystat,    0, 0, NULLCHAR,
  224. #endif
  225.     "attach",    doattach,    0, 2,
  226.         "attach <hardware> <hw specific options>",
  227. #ifdef    AX25
  228.     "ax25",        doax25,        0, 0, NULLCHAR,
  229. #endif
  230. #ifdef    BOOTP
  231.     "bootp",    dobootp,    0, 0, NULLCHAR,
  232.     "bootpd",    bootpdcmd,    0, 0, NULLCHAR,
  233. #endif
  234. /* This one is out of alpabetical order to allow abbreviation to "c" */
  235. #ifdef    AX25
  236.     "connect",    doconnect,    1024, 3,
  237.     "connect <interface> <callsign>",
  238. #endif
  239. #if    !defined(UNIX) && !defined(AMIGA)
  240.     "cd",        docd,        0, 0, NULLCHAR,
  241. #endif
  242.     "close",    doclose,    0, 0, NULLCHAR,
  243. /* This one is out of alpabetical order to allow abbreviation to "d" */
  244.     "disconnect",    doclose,    0, 0, NULLCHAR,
  245.     "delete",    dodelete,    0, 2, "delete <file>",
  246.     "detach",    dodetach,    0, 2, "detach <interface>",
  247. #ifdef    DIALER
  248.     "dialer",    dodialer,    512, 2,
  249.     "dialer <iface> [<file> [<seconds> [<pings> [<hostid>]]]]",
  250. #endif
  251. #ifndef    AMIGA
  252.     "dir",        dodir,        512, 0, NULLCHAR, /* note sequence */
  253. #endif
  254.     "domain",    dodomain,    0, 0, NULLCHAR,
  255. #ifdef    DRSI
  256.     "drsistat",    dodrstat,    0, 0, NULLCHAR,
  257. #endif
  258. #ifdef    EAGLE
  259.     "eaglestat",    doegstat,    0, 0, NULLCHAR,
  260. #endif
  261.     "echo",        doecho,        0, 0, NULLCHAR,
  262.     "eol",        doeol,        0, 0, NULLCHAR,
  263. #if    !defined(MSDOS)
  264.     "escape",    doescape,    0, 0, NULLCHAR,
  265. #endif
  266. #ifdef    PC_EC
  267.     "etherstat",    doetherstat,    0, 0, NULLCHAR,
  268. #endif
  269.     "exit",        doexit,        0, 0, NULLCHAR,
  270.     "finger",    dofinger,    1024, 2, "finger name@host",
  271.     "ftp",        doftp,        2048, 2, "ftp <address>",
  272. #ifdef HAPN
  273.     "hapnstat",    dohapnstat,    0, 0, NULLCHAR,
  274. #endif
  275.     "help",        dohelp,        0, 0, NULLCHAR,
  276. #ifdef    HOPCHECK
  277.     "hop",        dohop,        0, 0, NULLCHAR,
  278. #endif
  279.     "hostname",    dohostname,    0, 0, NULLCHAR,
  280. #ifdef    HS
  281.     "hs",        dohs,        0, 0, NULLCHAR,
  282. #endif
  283.     "icmp",        doicmp,        0, 0, NULLCHAR,
  284.     "ifconfig",    doifconfig,    0, 0, NULLCHAR,
  285.     "ip",        doip,        0, 0, NULLCHAR,
  286. #ifdef    MSDOS
  287.     "isat",        doisat,        0, 0, NULLCHAR,
  288. #endif
  289.     "kick",        dokick,        0, 0, NULLCHAR,
  290.     "log",        dolog,        0, 0, NULLCHAR,
  291. #ifdef    MAILBOX
  292.     "mbox",        dombox,        0, 0, NULLCHAR,
  293. #endif
  294. #ifndef    UNIX
  295.     "memory",    domem,        0, 0, NULLCHAR,
  296. #endif
  297.     "mkdir",    domkd,        0, 2, "mkdir <directory>",
  298. #ifdef    AX25
  299.     "mode",        domode,        0, 2, "mode <interface>",
  300. #endif
  301.     "more",        domore,        512, 2, "more <filename>",
  302. #ifdef    NETROM
  303.     "netrom",    donetrom,    0, 0, NULLCHAR,
  304. #endif    /* NETROM */
  305. #ifdef    NNTP
  306.     "nntp",        donntp,        0, 0, NULLCHAR,
  307. #endif    /* NNTP */
  308. #ifdef    NRS
  309.     "nrstat",    donrstat,    0, 0, NULLCHAR,
  310. #endif    /* NRS */
  311.     "param",    doparam,    0, 2, "param <interface>",
  312.     "ping",        doping,        512, 2,
  313.     "ping <hostid> [<length> [<interval> [incflag]]]",
  314. #ifdef    PI
  315.     "pistatus",    dopistat,    0, 0, NULLCHAR,
  316. #endif
  317. #ifdef POP
  318.     "pop",        dopop,        0, 0, NULLCHAR,
  319. #endif
  320. #ifdef PPP
  321.     "ppp",        doppp_commands,    0, 0, NULLCHAR,
  322. #endif
  323.     "ps",        ps,        0, 0, NULLCHAR,
  324. #if    !defined(UNIX) && !defined(AMIGA)
  325.     "pwd",        docd,        0, 0, NULLCHAR,
  326. #endif
  327.     "record",    dorecord,    0, 0, NULLCHAR,
  328.     "remote",    doremote,    0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick",
  329.     "rename",    dorename,    0, 3, "rename <oldfile> <newfile>",
  330.     "reset",    doreset,    0, 0, NULLCHAR,
  331. #ifdef    RIP
  332.     "rip",        dorip,        0, 0, NULLCHAR,
  333. #endif
  334.     "rmdir",    dormd,        0, 2, "rmdir <directory>",
  335.     "route",    doroute,    0, 0, NULLCHAR,
  336.     "session",    dosession,    0, 0, NULLCHAR,
  337. #ifdef    SCC
  338.     "sccstat",    dosccstat,    0, 0, NULLCHAR,
  339. #endif
  340. #if    !defined(AMIGA)
  341.     "shell",    doshell,    0, 0, NULLCHAR,
  342. #endif
  343.     "smtp",        dosmtp,        0, 0, NULLCHAR,
  344.     "socket",    dosock,        0, 0, NULLCHAR,
  345. #ifdef    SERVERS
  346.     "start",    dostart,    0, 2, "start <servername>",
  347.     "stop",        dostop,        0, 2, "stop <servername>",
  348. #endif
  349.     "tcp",        dotcp,        0, 0, NULLCHAR,
  350.     "telnet",    dotelnet,    1024, 2, "telnet <address>",
  351.     "test",        dotest,        0, 0, NULLCHAR,
  352.     "tip",        dotip,        256, 2, "tip <iface>",
  353. #ifdef    TRACE
  354.     "trace",    dotrace,    0, 0, NULLCHAR,
  355. #endif
  356.     "udp",        doudp,        0, 0, NULLCHAR,
  357.     "upload",    doupload,    0, 0, NULLCHAR,
  358. #ifdef    MSDOS
  359.     "watch",    doswatch,    0, 0, NULLCHAR,
  360. #endif
  361.     "?",        dohelp,        0, 0, NULLCHAR,
  362.     NULLCHAR,    NULLFP,        0, 0,
  363.         "Unknown command; type \"?\" for list",
  364. };
  365.  
  366. /* List of supported hardware devices */
  367. struct cmds Attab[] = {
  368. #ifdef    PC_EC
  369.     /* 3-Com Ethernet interface */
  370.     "3c500", ec_attach, 0, 7,
  371.     "attach 3c500 <address> <vector> arpa <label> <buffers> <mtu> [ip_addr]",
  372. #endif
  373. #ifdef    ASY
  374.     /* Ordinary PC asynchronous adaptor */
  375.     "asy", asy_attach, 0, 8,
  376. #ifndef    AMIGA
  377.     "attach asy <address> <vector> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
  378. #else
  379.     "attach asy <driver> <unit> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
  380. #endif    /* AMIGA */
  381. #endif    /* ASY */
  382. #ifdef    PC100
  383.     /* PACCOMM PC-100 8530 HDLC adaptor */
  384.     "pc100", pc_attach, 0, 8,
  385.     "attach pc100 <address> <vector> ax25 <label> <buffers>\
  386.  <mtu> <speed> [ip_addra] [ip_addrb]",
  387. #endif
  388. #ifdef    DRSI
  389.     /* DRSI PCPA card in low speed mode */
  390.     "drsi", dr_attach, 0, 8,
  391.     "attach drsi <address> <vector> ax25 <label> <bufsize> <mtu>\
  392. <chan a speed> <chan b speed> [ip addr a] [ip addr b]",
  393. #endif
  394. #ifdef    EAGLE
  395.     /* EAGLE RS-232C 8530 HDLC adaptor */
  396.     "eagle", eg_attach, 0, 8,
  397.     "attach eagle <address> <vector> ax25 <label> <buffers>\
  398.  <mtu> <speed> [ip_addra] [ip_addrb]",
  399. #endif
  400. #ifdef    PI
  401.     /* PI 8530 HDLC adaptor */
  402.     "pi", pi_attach, 0, 8,
  403.     "attach pi <address> <vector> <dmachannel> ax25 <label> <buffers>\
  404.  <mtu> <speed> [ip_addra] [ip_addrb]",
  405. #endif
  406. #ifdef    HAPN
  407.     /* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
  408.     "hapn", hapn_attach, 0, 8,
  409.     "attach hapn <address> <vector> ax25 <label> <rx bufsize>\
  410.  <mtu> csma|full [ip_addr]",
  411. #endif
  412. #ifdef    APPLETALK
  413.     /* Macintosh AppleTalk */
  414.     "0", at_attach, 0, 7,
  415.     "attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu> [ip_addr]",
  416. #endif
  417. #ifdef NETROM
  418.     /* fake netrom interface */
  419.     "netrom", nr_attach, 0, 1,
  420.     "attach netrom [ip_addr]",
  421. #endif
  422. #ifdef    PACKET
  423.     /* FTP Software's packet driver spec */
  424.     "packet", pk_attach, 0, 4,
  425.     "attach packet <int#> <label> <buffers> <mtu> [ip_addr]",
  426. #endif
  427. #ifdef    HS
  428.     /* Special high speed driver for DRSI PCPA or Eagle cards */
  429.     "hs", hs_attach, 0, 7,
  430.     "attach hs <address> <vector> ax25 <label> <buffers> <mtu>\
  431.  <txdelay> <persistence> [ip_addra] [ip_addrb]",
  432. #endif
  433. #ifdef SCC
  434.     "scc", scc_attach, 0, 7,
  435.     "attach scc <devices> init <addr> <spacing> <Aoff> <Boff> <Dataoff>\n"
  436.     "   <intack> <vec> [p]<clock> [hdwe] [param]\n"
  437.     "attach scc <chan> slip|kiss|nrs|ax25 <label> <mtu> <speed> <bufsize> [call] ",
  438. #endif
  439.     NULLCHAR,
  440. };
  441.  
  442. /* Functions to be called on each clock tick */
  443. void (*Cfunc[])() = {
  444.     pctick,    /* Call PC-specific stuff to keep time */
  445.     kbint,    /* Necessary because there's no hardware keyboard interrupt */
  446.     refiq,    /* Replenish interrupt pool */
  447. #ifdef    ASY
  448.     asytimer,
  449. #endif
  450. #ifdef    SCC
  451.     scctimer,
  452. #endif
  453.     NULL,
  454. };
  455.  
  456. /* Entry points for garbage collection */
  457. void (*Gcollect[])() = {
  458.     tcp_garbage,
  459.     ip_garbage,
  460.     udp_garbage,
  461.     st_garbage,
  462. #ifdef    AX25
  463.     lapb_garbage,
  464. #endif
  465. #ifdef    NETROM
  466.     nr_garbage,
  467. #endif
  468.     NULL
  469. };
  470.  
  471. /* Functions to be called at shutdown */
  472. void (*Shutdown[])() = {
  473. #ifdef    SCC
  474.     sccstop,
  475. #endif
  476.     uchtimer,    /* Unlink timer handler from timer chain */
  477.     NULLVFP,
  478. };
  479.  
  480. /* Packet tracing stuff */
  481. #ifdef    TRACE
  482. #include "trace.h"
  483.  
  484. /* Protocol tracing function pointers. Matches list of class definitions
  485.  * in pktdrvr.h.
  486.  */
  487. struct trace Tracef[] = {
  488.     NULLFP,        ip_dump,    /* CL_NONE */
  489.  
  490. #ifdef    ETHER                /* CL_ETHERNET */
  491.     ether_forus,    ether_dump,
  492. #else
  493.     NULLFP,        NULLVFP,
  494. #endif    /* ETHER */
  495.  
  496.     NULLFP,        NULLVFP,    /* CL_PRONET_10 */
  497.     NULLFP,        NULLVFP,    /* CL_IEEE8025 */
  498.     NULLFP,        NULLVFP,    /* CL_OMNINET */
  499.  
  500. #ifdef    APPLETALK
  501.     at_forus,    at_dump,    /* CL_APPLETALK */
  502. #else
  503.     NULLFP,        NULLVFP,
  504. #endif    /* APPLETALK */
  505.  
  506. #ifdef VJCOMPRESS
  507.     NULLFP,        sl_dump,    /* CL_SERIAL_LINE */
  508. #else
  509.     NULLFP,        ip_dump,    /* CL_SERIAL_LINE */
  510. #endif
  511.     NULLFP,        NULLVFP,    /* CL_STARLAN */
  512.  
  513. #ifdef    ARCNET
  514.     arc_forus,    arc_dump,    /* CL_ARCNET */
  515. #else
  516.     NULLFP,        NULLVFP,
  517. #endif    /* ARCNET */
  518.  
  519. #ifdef    AX25
  520.     ax_forus,    ax25_dump,    /* CL_AX25 */
  521. #else
  522.     NULLFP,        NULLVFP,
  523. #endif    /* AX25 */
  524.  
  525. #ifdef    KISS                /* CL_KISS */
  526.     ki_forus,    ki_dump,
  527. #else
  528.     NULLFP,        NULLVFP,
  529. #endif    /* KISS */
  530.  
  531.     NULLFP,        NULLVFP,    /* CL_IEEE8023 */
  532.     NULLFP,        NULLVFP,    /* CL_FDDI */
  533.     NULLFP,        NULLVFP,    /* CL_INTERNET_X25 */
  534.     NULLFP,        NULLVFP,    /* CL_LANSTAR */
  535.     NULLFP,        ip_dump,    /* CL_SLFP */
  536.  
  537. #ifdef    NETROM                /* CL_NETROM */
  538.     NULLFP,        ip_dump,
  539. #else
  540.     NULLFP,        NULLVFP,
  541. #endif
  542.  
  543. #ifdef PPP
  544.     NULLFP,        ppp_dump,    /* CL_PPP */
  545. #else
  546.     NULLFP,        NULLVFP,
  547. #endif /* PPP */
  548. };
  549.  
  550. #else    /* TRACE */
  551.  
  552. /* Stub for packet dump function */
  553. void
  554. dump(iface,direction,type,bp)
  555. struct iface *iface;
  556. int direction;
  557. unsigned type;
  558. struct mbuf *bp;
  559. {
  560. }
  561. void
  562. raw_dump(iface,direction,bp)
  563. struct iface *iface;
  564. int direction;
  565. struct mbuf *bp;
  566. {
  567. }
  568.  
  569. #endif    /* TRACE */
  570.  
  571.  
  572. #ifdef    AX25
  573. /* Hooks for passing incoming AX.25 data frames to network protocols */
  574. static void
  575. axip(iface,axp,src,dest,bp,mcast)
  576. struct iface *iface;
  577. struct ax25_cb *axp;
  578. char *src;
  579. char *dest;
  580. struct mbuf *bp;
  581. int mcast;
  582. {
  583.     (void)ip_route(iface,bp,mcast);
  584. }
  585.  
  586. static void
  587. axarp(iface,axp,src,dest,bp,mcast)
  588. struct iface *iface;
  589. struct ax25_cb *axp;
  590. char *src;
  591. char *dest;
  592. struct mbuf *bp;
  593. int mcast;
  594. {
  595.     (void)arp_input(iface,bp);
  596. }
  597.  
  598. #ifdef    NETROM
  599. static void
  600. axnr(iface,axp,src,dest,bp,mcast)
  601. struct iface *iface;
  602. struct ax25_cb *axp;
  603. char *src;
  604. char *dest;
  605. struct mbuf *bp;
  606. int mcast;
  607. {
  608.     if(!mcast)
  609.         nr_route(bp,axp);
  610.     else
  611.         nr_nodercv(iface,src,bp);
  612. }
  613.  
  614. #endif    /* NETROM */
  615. #endif    /* AX25 */
  616.  
  617. #ifndef    RIP
  618. /* Stub for routing timeout when RIP is not configured -- just remove entry */
  619. void
  620. rt_timeout(s)
  621. void *s;
  622. {
  623.     struct route *stale = (struct route *)s;
  624.  
  625.     rt_drop(stale->target,stale->bits);
  626. }
  627. #endif
  628.  
  629. #ifdef    SERVERS
  630. /* "start" and "stop" subcommands */
  631. static struct cmds Startcmds[] = {
  632. #if    defined(AX25) && defined(MAILBOX)
  633.     "ax25",        ax25start,    256, 0, NULLCHAR,
  634. #endif
  635.     "discard",    dis1,        256, 0, NULLCHAR,
  636.     "echo",        echo1,        256, 0, NULLCHAR,
  637.     "finger",    finstart,    256, 0, NULLCHAR,
  638.     "ftp",        ftpstart,    256, 0, NULLCHAR,
  639. #if    defined(NETROM) && defined(MAILBOX)
  640.     "netrom",    nr4start,    256, 0, NULLCHAR,
  641. #endif
  642. #ifdef POP
  643.     "pop",        pop1,        256, 0, NULLCHAR,
  644. #endif
  645. #ifdef    RIP
  646.     "rip",        doripinit,    0,   0, NULLCHAR,
  647. #endif
  648.     "smtp",        smtp1,        256, 0, NULLCHAR,
  649. #if    defined(MAILBOX)
  650.     "telnet",    telnet1,    256, 0, NULLCHAR,
  651.     "tip",        tipstart,    256, 2, "start tip <interface>",
  652. #endif
  653.     "ttylink",    ttylstart,    256, 0, NULLCHAR,
  654.     "remote",    rem1,        768, 0, NULLCHAR,
  655.     NULLCHAR,
  656. };
  657. static struct cmds Stopcmds[] = {
  658. #if    defined(AX25) && defined(MAILBOX)
  659.     "ax25",        ax250,        0, 0, NULLCHAR,
  660. #endif
  661.     "discard",    dis0,        0, 0, NULLCHAR,
  662.     "echo",        echo0,        0, 0, NULLCHAR,
  663.     "finger",    fin0,        0, 0, NULLCHAR,
  664.     "ftp",        ftp0,        0, 0, NULLCHAR,
  665. #if    defined(NETROM) && defined(MAILBOX)
  666.     "netrom",    nr40,        0, 0, NULLCHAR,
  667. #endif
  668. #ifdef    POP
  669.     "pop",        pop0,        0, 0, NULLCHAR,
  670. #endif
  671. #ifdef    RIP
  672.     "rip",        doripstop,    0, 0, NULLCHAR,
  673. #endif
  674.     "smtp",        smtp0,        0, 0, NULLCHAR,
  675. #ifdef    MAILBOX
  676.     "telnet",    telnet0,    0, 0, NULLCHAR,
  677.     "tip",        tip0,        0, 2, "stop tip <interface>",
  678. #endif
  679.     "ttylink",    ttyl0,        0, 0, NULLCHAR,
  680.     "remote",    rem0,        0, 0, NULLCHAR,
  681.     NULLCHAR,
  682.  
  683. };
  684. static int
  685. dostart(argc,argv,p)
  686. int argc;
  687. char *argv[];
  688. void *p;
  689. {
  690.     return subcmd(Startcmds,argc,argv,p);
  691. }
  692. static int
  693. dostop(argc,argv,p)
  694. int argc;
  695. char *argv[];
  696. void *p;
  697. {
  698.     return subcmd(Stopcmds,argc,argv,p);
  699. }
  700. #endif    /* SERVERS */
  701.  
  702. /* Various configuration-dependent functions */
  703.  
  704. /* put mbuf into Hopper for network task
  705.  * returns 0 if OK
  706.  */
  707. int
  708. net_route(ifp, type, bp)
  709. struct iface *ifp;
  710. int type;
  711. struct mbuf *bp;
  712. {
  713.     struct mbuf *nbp;
  714.     struct phdr phdr;
  715.  
  716.     phdr.iface = ifp;
  717.     phdr.type = type;
  718.  
  719.     if ((nbp = pushdown(bp,sizeof(phdr))) == NULLBUF ){
  720.         return -1;
  721.     }
  722.     memcpy( &nbp->data[0],(char *)&phdr,sizeof(phdr));
  723.     enqueue(&Hopper,nbp);
  724.     /* Especially on slow machines, serial I/O can be quite
  725.      * compute intensive, so release the machine before we
  726.      * do the next packet.  This will allow this packet to
  727.      * go on toward its ultimate destination. [Karn]
  728.      */
  729.     pwait(NULL);
  730.     return 0;
  731. }
  732.  
  733.  
  734. /* Process packets in the Hopper */
  735. static void
  736. network(i,v1,v2)
  737. int i;
  738. void *v1;
  739. void *v2;
  740. {
  741.     struct mbuf *bp;
  742.     struct phdr phdr;
  743.     char i_state;
  744.  
  745. loop:
  746.     refiq();    /* Replenish interrupt buffer pool */
  747.  
  748.     i_state = dirps();
  749.     while(Hopper == NULLBUF)
  750.         pwait(&Hopper);
  751.     restore(i_state);
  752.  
  753.     /* Process the input packet */
  754.     bp = dequeue(&Hopper);
  755.     pullup(&bp,(char *)&phdr,sizeof(phdr));
  756.     if(phdr.iface != NULLIF){
  757.         phdr.iface->rawrecvcnt++;
  758.         phdr.iface->lastrecv = secclock();
  759.     }
  760.     dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
  761.     switch(phdr.type){
  762. #ifdef    KISS
  763.     case CL_KISS:
  764.         kiss_recv(phdr.iface,bp);
  765.         break;
  766. #endif
  767. #ifdef    AX25
  768.     case CL_AX25:
  769.         ax_recv(phdr.iface,bp);
  770.         break;
  771. #endif
  772. #ifdef    ETHER
  773.     case CL_ETHERNET:
  774.         eproc(phdr.iface,bp);
  775.         break;
  776. #endif
  777. #ifdef ARCNET
  778.     case CL_ARCNET:
  779.         aproc(phdr.iface,bp);
  780.         break;
  781. #endif
  782. #ifdef PPP
  783.     case CL_PPP:
  784.         ppp_proc(phdr.iface,bp);
  785.         break;
  786. #endif
  787.     /* These types have no link layer protocol at the point when they're
  788.      * put in the hopper, so they can be handed directly to IP. The
  789.      * separate types are just for user convenience when running the
  790.      * "iface" command.
  791.      */
  792.     case CL_NONE:
  793.     case CL_SERIAL_LINE:
  794.     case CL_SLFP:
  795.         ip_route(phdr.iface,bp,0);
  796.         break;
  797.     default:
  798.         free_p(bp);
  799.         break;
  800.     }
  801.     /* Let everything else run - this keeps the system from wedging
  802.      * when we're hit by a big burst of packets
  803.      */
  804.     pwait(NULL);
  805.     goto loop;
  806. }
  807.  
  808. int
  809. dotest(argc,argv,p)
  810. int argc;
  811. char *argv[];
  812. void *p;
  813. {
  814.     long i;
  815.     int32 oldtime = 0;
  816.     int32 newtime;
  817.  
  818.     Current->flowmode = 1;
  819.     for(i=0;i<40000;i++){
  820.         newtime = msclock();
  821.         if(newtime < oldtime){
  822.             tprintf("Clock slip %ld: %ld - %ld = %ld\n",i,
  823.                 newtime,oldtime,newtime-oldtime);
  824.         } else
  825.             oldtime = newtime;
  826.     }
  827.     pwait(NULL);
  828.     Current->flowmode = 0;
  829.     return 0;
  830. }
  831.  
  832.